﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using YJKRevitArea.AreaSet;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YJKRevitRoom.Utility;

namespace YJKInspectModel.CheckForMiniWall
{
	internal class CheckForMiniWall
	{
		public CheckForMiniWall(ExternalCommandData cmdData)
		{
			this.m_cmdData = cmdData;
			this.m_doc = cmdData.Application.ActiveUIDocument.Document;
			this.m_selection = this.m_cmdData.Application.ActiveUIDocument.Selection;
		}

		private bool GetTolRooms()
		{
			this.m_cmdData.Application.ActiveUIDocument.Selection.GetElementIds();
			List<Room> rooms = YJKRevitRoom.Utility.Common.GetRooms(this.m_doc, this.m_cmdData.Application.ActiveUIDocument.ActiveView.Id);
			this.m_lstRooms = rooms;
			if (rooms.Count == 0)
			{
				YJKMessageBox.Show("未发现房间边界，请先设置房间!");
				return false;
			}
			return true;
		}

		private bool GetTolMiniWallPts()
		{
			List<Curve> roomCurvesWithoutInstance = AreaCreator.GetRoomCurvesWithoutInstance(this.m_doc, this.m_lstRooms);
			List<XYZ> list = new List<XYZ>();
			AreaCreator.AdjustCurves(ref roomCurvesWithoutInstance, ref list, this.m_doc);
			if (list.Count > 0)
			{
				string str = list.Count.ToString();
				if (MessageBox.Show("中心线错位小于0.8mm的墙体有" + str + "个，是否处理？(提示线需用户手动删除)", "盈建科提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					AreaCreator.CreateCurvesForErrorPos(list, this.m_doc);
				}
				return false;
			}
			YJKMessageBox.Show("没有出现问题的构件!");
			return true;
		}

		public bool CheckCurLevel()
		{
			return this.GetTolRooms() && this.GetTolMiniWallPts();
		}

		private ExternalCommandData m_cmdData;

		private Document m_doc;

		private Selection m_selection;

		private List<Room> m_lstRooms;
	}
}
